package com.jiuyou.clientController.staff;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.staff.domain.Staff;
import com.ruoyi.staff.service.IStaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 人员信息Controller
 *
 * @author ruoyi
 * @date 2025-05-07
 */
@RestController
@RequestMapping("/client/staff")
public class ClientStaffController extends BaseController
{
    @Autowired
    private IStaffService staffService;

    /**
     * 查询人员信息列表
     */
    @GetMapping("/listAll")
    public AjaxResult listAll()
    {
        Staff staff = new Staff();
        List<Staff> list = staffService.selectStaffList(staff);

        for(Staff one:list){


        }

        return AjaxResult.success(list);
    }

    /**
     * 查询人员信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Staff staff)
    {
        startPage();
        List<Staff> list = staffService.selectStaffList(staff);
        return getDataTable(list);
    }

    /**
     * 导出人员信息列表
     */
    @Log(title = "人员信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Staff staff)
    {
        List<Staff> list = staffService.selectStaffList(staff);
        ExcelUtil<Staff> util = new ExcelUtil<Staff>(Staff.class);
        return util.exportExcel(list, "人员信息数据");
    }

    /**
     * 获取人员信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(staffService.selectStaffById(id));
    }

    /**
     * 新增人员信息
     */
    @Log(title = "人员信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Staff staff)
    {
        return toAjax(staffService.insertStaff(staff));
    }

    /**
     * 修改人员信息
     */
    @Log(title = "人员信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Staff staff)
    {
        staff.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(staffService.updateStaff(staff));
    }

    /**
     * 删除人员信息
     */
    @Log(title = "人员信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(staffService.logicDeleteStaff(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
